<template>
<h1>循环指令</h1>
  <ul>
    <li v-for="item in 5">Hello{{item}}</li>
  </ul>
  <hr>
  <ul v-for="item in 3">
    <li>Hello{{item}}</li>
    <li>Hello{{item}}</li>
    <li>Hello{{item}}</li>

    <ul v0for="p in productArr">
      <li>{{p}}</li>
    </ul>
    <hr>
    <table border="1">
      <tr>
        <th>商品编号</th>
        <th>商品名称</th>
        <th>商品价格</th>
        <th>商品数量</th>
        <th>操作</th>
      </tr>
      <tr v-for="(p,index) in productArr">
        <td>{{index+1}}</td>
        <td>{{p.title}}</td>
        <td>{{p.price}}</td>
        <td>{{p.num}}</td>
        <td><button @click="del(index)">删除</button></td>
      </tr>
    </table>
  </ul>
</template>

<script setup>
import { ref } from 'vue'
const productArr = ref([
  {title: "葡萄", price: 10, num: 100},
  {title: "苹果", price: 20, num: 200},
  {title: "西瓜", price: 30, num: 300},
  {title: "香蕉", price: 40, num: 400},
])
const del = (index)=>{
  if (confirm("是否删除")){
    productArr.value.splice(index, 1)
  }
}
</script>

<style scoped>

</style>